/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 苏李涛
 * Date: 2024-11-18
 * Time: 0:25
 */

//动态规划一>乘积最大子数组
public class Demo {
    public int maxProduct(int[] nums) {
        int n = nums.length;
        int[] f = new int[n+1];
        int[] g = new int[n+1];

        f[0] = g[0] = 1;
        int ret = -0x3f3f3f3f;
        for(int i = 1; i <= n; i++){
            int x = nums[i-1];
            f[i] = Math.max(x,Math.max(g[i-1]*x,f[i-1]*x));
            g[i] = Math.min(x,Math.min(g[i-1]*x,f[i-1]*x));
            ret = Math.max(ret,f[i]);
        }

        return ret;
    }
}
